<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class ReFund extends Model
{
    use SoftDeletes;

    const USABLE = 0;
    const CLOSED = 1;//已经通过
    const CANCELED = 2;//已经撤销

    protected $table = 'refund';
    protected $fillable = [
        'state', 'refund_desc', 'chest_id', 'grip_id', 'type_id', 'user_id', 'amount'
    ];

    //获取用户信息
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
    

    public function isClosed()
    {
        return self::CLOSED == $this->state;
    }

    public function isUsable()
    {
        return self::USABLE == $this->state;
    }


    public function cancel()
    {
        $this->update([
            'state' => self::CANCELED
        ]);
    }
}
